package com.thread;

import java.io.DataInputStream;
import java.net.Socket;

public class TCPthread extends Thread{
    // 接收Socket对象
    private Socket socket;
    public TCPthread(Socket socket) {
        this.socket = socket;
    }
    @Override
    public void run() {

            try(DataInputStream inputStream = new DataInputStream(socket.getInputStream());) {
                while (true) {
                    System.out.println(inputStream.readUTF());
                    System.out.println("收到来自" + socket.getInetAddress().getHostAddress() + "的数据包，端口号：" + socket.getPort());
                    System.out.println("===========================================");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
    }
}
